import Vue from 'vue';
import App from './App';

// #ifdef H5
// const vconsole = require('vconsole')
// Vue.prototype.$vconsole = new vconsole()
// #endif

// 引入uview-ui
import uView from 'uview-ui';
Vue.use(uView);

// 引入uview-ui提供的对vuex的简写法文件
import store from '@/script/store.js';
let vuexStore = require('@/script/mixin.js');
Vue.mixin(vuexStore);

// region 路由处理 +++++
import {
    router,
    RouterMount
} from '@/script/router.js';
Vue.use(router);
// endregion

import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn.js';
// import updateLocale from 'dayjs/plugin/updateLocale';
// import relativeTime from 'dayjs/plugin/relativeTime';
// dayjs.extend(updateLocale);
// dayjs.extend(relativeTime);
dayjs.locale('zh-cn');

// 引入配置文件
import config from '@/script/config.js';
import wx from '@/script/wx.js';
import mc from '@/script/mc.js';
// 配置
Vue.prototype.$config = config;
Vue.prototype.$wx = wx;
Vue.prototype.$mc = mc;
Vue.prototype.$dayjs = dayjs;

// region 客户端类型判断 +++++
Vue.prototype.clientType = 'browser_computer';
// #ifdef H5
const ua = window.navigator.userAgent.toLowerCase();
if ('ontouchstart' in window) {
    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        Vue.prototype.clientType = 'wechat_mobile';
    } else {
        Vue.prototype.clientType = 'browser_mobile';
    }
} else {
    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        Vue.prototype.clientType = 'wechat_computer';
    }
}
// #endif
// endregion

// region 初始化处理方案 +++++
Vue.prototype.$appLaunch = new Promise((resolve, reject) => {
    Vue.prototype.$appLaunchResolve = resolve;
    Vue.prototype.$appLaunchReject = reject;
});
// endregion

Vue.config.productionTip = false;

App.mpType = 'app';

const app = new Vue({
    store,
    ...App
});

// http拦截器，将此部分放在new Vue()和app.$mount()之间，才能App.vue中正常使用
import httpInterceptor from '@/script/http.interceptor.js';
Vue.use(httpInterceptor, app);

// http接口API抽离，免于写url或者一些固定的参数
import httpApi from '@/script/http.api.js';
Vue.use(httpApi, app);

// #ifdef H5
RouterMount(app, router, '#app')
// #endif

// #ifndef H5
app.$mount(); //为了兼容小程序及app端必须这样写才有效果
// #endif
